package com.lumlord.common.database;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * 数据切换监听器
 * @author GPF
 *
 */
public class DynamicDataSource extends AbstractRoutingDataSource  {
	
	public String getCurrent() {
		if(null == DBContextHolder.get()) {
			return null;
		}
		
		return DBContextHolder.get().name();
	}
	
	 public  void master() {
		 DBContextHolder.set(DBContextHolder.DBTypeEnum.MASTER);
	 }
	
	
	@Override
	protected Object determineCurrentLookupKey() {
		  return DBContextHolder.get();
	}

}